﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace _03_反射调用泛型方法
{
    class Program
    {
        static void Main(string[] args)
        {
            // 反射调用泛型方法
            MethodInfo method1 = typeof(Sample).GetMethod("GenericMethod");
            MethodInfo generic1 = method1.MakeGenericMethod(typeof(string));
            generic1.Invoke(new Sample(), null);

            // 反射调用静态泛型方法
            MethodInfo method2 = typeof(Sample).GetMethod("StaticMethod");
            MethodInfo generic2 = method2.MakeGenericMethod(typeof(string));
            generic2.Invoke(null, null);

            Console.ReadKey();

        }
    }

    public class Sample
    {
        public void GenericMethod<T>()
        {
            Console.WriteLine("GenericMethod<T>()");
        }
        public static void StaticMethod<T>()
        {
            Console.WriteLine("StaticMethod<T>()");
        }
    }

}
